package com.hins.demo.gatewayimpl;

import com.hins.demo.convertor.ItemConvertor;
import com.hins.demo.gateway.ItemGateway;
import com.hins.demo.model.order.Item;
import com.hins.demo.rpc.ExternalItemService;
import com.hins.demo.rpc.dataobject.ItemDO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class ItemGatewayImpl implements ItemGateway {

    @Resource
    private ExternalItemService externalItemService;
    
    @Resource
    private ItemConvertor itemConvertor;

    @Override
    public Item getItem(Long itemId) {
        ItemDO itemDO = externalItemService.getItem(itemId); // 外部服务
        if (itemDO != null) {
            return itemConvertor.toItem(itemDO); // 转化
        }
        return null;
    }
}